import java.security.PublicKey;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.*;
import java.util.stream.IntStream;

/**
 * @Author: linzp
 * @Date: 2022/10/12/11:19
 */
public class demolam {
    private static ThreadPoolExecutor executor = new ThreadPoolExecutor(5000, 25000, 5L, TimeUnit.SECONDS,new LinkedBlockingQueue<>(1000));

    public static void main(String[] args) {
//        ConcurrentHashMap<String, Long> map = LongStream.rangeClosed(1, 10)
//                .boxed()
//                .collect(Collectors.toConcurrentMap(i -> UUID.randomUUID().toString(), Function.identity(),
//                        (o1, o2) -> o1, ConcurrentHashMap::new));
//        System.out.println(map);
//        System.out.println(UUID.randomUUID().toString());
//
//          IntStream.range(0, 10).mapToObj(i->new product()).collect(Collectors.toList());
//        IntStream.range(0,10).boxed().collect(Collectors.toList());
//        test();

//        testStream();

//        IntStream.rangeClosed(1, Integer.MAX_VALUE).parallel().forEach(i->{
//            Runnable task = ()->{
//                System.out.println(i);
//                try {
//                    Thread.sleep(3L);
//                } catch (InterruptedException e) {
//                    e.printStackTrace();
//                }
//                System.out.println(Thread.currentThread().getName());
//            };
//            executor.execute(task);
//        });

//        testFuture();
        testRunnable();
    }
    static void testFuture() {
        IntStream.rangeClosed(1, Integer.MAX_VALUE).parallel().forEach(i->{
            Callable task = (()->{
                System.out.println(i);
                try {
                    Thread.sleep(3L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName());
                return "null";
            });
            Future<String> future = executor.submit(task);

            try {
                System.out.println(future.get());
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        });

    }
    static void testRunnable() {
        Runnable runnable = (()->{
            System.out.println("1");
        });

        new Thread(() -> System.out.println("run..")).run();
    }

    static class product {
        public product() {
        }
    }

    static class User {
        private String email;

        public User() {
        }

        public String setEmail(String email) {
            this.email = email;
            return email;
        }

        public String getEmail() {
            return email;
        }
    }

    static void test() {
        User user = new User();
//        user.setEmail("1z");
        Optional.ofNullable(user)
                .map(user1 -> user1.getEmail()).orElse(user.setEmail("11"));

        System.out.println(user.getEmail());
    }

    static void testStream() {
        ArrayList<String> list = new ArrayList<>();
        list.add("11");
        Set<String> set = new HashSet<>(list);
        User user = new User();
        User user2 = new User();
        user.setEmail("11");
        user2.setEmail("121");
        ArrayList<User> users = new ArrayList<>();
        users.add(user);
        users.add(user2);
        System.out.println(users);
        users.stream().forEach(u -> {
            if (set.contains(u.getEmail())) {
                u.setEmail("gai");
            }
        });
        System.out.println(users);
        users.forEach(u -> {
            System.out.println(u.getEmail());
        });


    }
}
